<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <th:block th:include="include :: header('新增用户发布任务')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<style>
    .kv-file-upload {
        display: none;
    }

    .btn-file {
        float: right;
    }
</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-usertask-add">
        <input id="taskId" name="taskId" th:value="${taskId}" hidden>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">任务名称：</label>
            <div class="col-sm-8">
                <input name="taskName" class="form-control" placeholder="请输入任务名称" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">赏金：</label>
            <div class="col-sm-8">
                <input name="money" class="form-control" placeholder="请输入赏金" type="number" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">电话号码：</label>
            <div class="col-sm-8">
                <input id="phonenumber" name="phonenumber" class="form-control" placeholder="请输入电话号码" type="text"
                       maxlength="11" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">地址：</label>
            <div class="col-sm-8">
                <input name="address" class="form-control" placeholder="请输入地址" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">任务描述：</label>
            <div class="col-sm-8">
                <input name="taskDescription" class="form-control" placeholder="请输入任务描述" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片/视频：</label>
            <br/>
            <br/>
            <div class="file-loading col-sm-8">
                <input id="taskImageVideo" name="file" type="file" class="form-control" multiple>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "task/usertask"
    var taskId = [[${taskId}]];
    $("#form-usertask-add").validate({
        focusCleanup: true
    });

    $(document).ready(function () {
        $("#taskImageVideo").fileinput({
            theme: 'explorer-fas',//设置主题
            uploadUrl: prefix + "/uploadFiles",
            language: 'zh',
            overwriteInitial: false,
            initialPreviewAsData: true,
            showCaption: false,
            showRemove: true,
            showClose: false,
            showUpload: true,
            minFileSize: 0,
            maxFileSize: 102400,
            uploadExtraData: {
                "taskId": taskId
            },
            //允许最小文件上传个数
            minFileCount: 0,
            //允许最大文件上传个数
            maxFileCount: 4,
            //图片上传格式这样写
            allowedFileTypes: ['image', 'video', 'audio', 'flash'],//允许文件上传的格式
            allowedFileExtensions: ["jpg", "png", "gif", "mp4"]
        });
    });

    function submitHandler() {
        if ($.validate.form()) {
            // $('#taskId').attr("value",taskId);
            $.operate.save(prefix + "/add", $('#form-usertask-add').serialize());
        }
    }

    /*  function uploadFile() {
          $.modal.loading("文件上传中，请勿做其他操作，耐心等待");
          var formData = new FormData();
          if ($('#taskImageVideo')[0].files[0] == null) {
              $.modal.alertWarning("请先选择文件路径");
              return false;
          }
          for (var i = 0; i < $('#taskImageVideo')[0].files.length; i++) {
              formData.append('files', $('#taskImageVideo')[0].files[i]);
              console.log($('#taskImageVideo')[0].files[i]);
          }
          console.log($('#taskImageVideo')[0].files);
          $.ajax({
              url: prefix + "/uploadFiles",
              type: 'post',
              cache: false,
              data: formData,
              processData: false,
              contentType: false,
              dataType: "json",
              success: function (result) {
                  $.operate.successCallback(result);
                  $.modal.closeLoading();
              }
          });
      }*/

</script>
</body>
</html>